package org.nowcoder.leetcode.slidingWindow;


/**
 * Title  : 80. Remove Duplicates from Sorted Array II
 * Source : https://leetcode.cn/problems/remove-duplicates-from-sorted-array-ii/?envType=study-plan-v2&envId=top-interview-150
 * Author : XrazYang
 * Date   : 2023-07-06
 */
public class LeetCode_80 {
    public int removeDuplicates(int[] nums) {
        int i = 0, k = 1;
        for (; k < nums.length; k++) {
            if (nums[i] < nums[k]) {
                nums[++i] = nums[k];
            } else if (nums[i] == nums[k]) {
                if (i < 1 || nums[i - 1] != nums[k]) {
                    nums[++i] = nums[k];
                }
            }
        }
        return i + 1;
    }
}
